--
-- Created by IntelliJ IDEA.
-- User: mind
-- Date: 2016/4/15
-- Time: 11:50
-- 步骤：传入当前栏目，contoller（模块）和 action（方法）
-- 功能：返回网站栏目列表。让栏目自动选中
--

--传入当前栏目，contoller（模块）和 action（方法）
local function getNav(c,a)
    --栏目菜单列表
    local nav_list = {
        {
            menu = "管理员后台",
            sub = {
                {
                    c = "admin",
                    a = "index",
                    url = "/admin/index",
                    name = "后台首页"
                }
            }
        },
        {
            menu = "内容管理",
            sub = {
                {
                    c = "admin",
                    a = "cate_list",
                    url = "/admin/cate_list",
                    name = "栏目管理",
                    items = {
                        {c = "admin",a = "cate_add"},
                        {c = "admin",a = "cate_edit"}
                    }
                },
                {
                    c = "admin",
                    a = "post_list",
                    url = "/admin/post_list?page=1&rows=10&status=1",
                    name = "文章管理",
                    items = {
                        {c = "admin",a = "post_add"},
                        {c = "admin",a = "post_edit"}
                    }
                }
            }
        },
        {
            menu = "网站设置",
            sub = {
                {
                    c = "admin",
                    a = "setting",
                    url = "/admin/setting",
                    name = "基本设置"
                },
                {
                    c = "admin",
                    a = "user",
                    url = "/admin/user",
                    name = "用户设置"
                },
                {
                    c = "admin",
                    a = "logout",
                    url = "/admin/logout",
                    name = "退出登录"
                }
            }
        }
    }

    --让当前栏目选中
    for k, v in pairs(nav_list) do
        for k2, v2 in pairs(v.sub) do
            if v2.c ==c and v2.a == a then
                nav_list[k].sub[k2].current = true
            else
                --有栏目下属功能的情况下
                if v2.items then
                    --让父栏目同样是选中状态
                    for k3,v3  in pairs(v2.items) do
                        if v3.c ==c and v3.a == a then
                            nav_list[k].sub[k2].current = true
                        end
                    end
                end
            end    
        end
    end

    return nav_list
end

return getNav
